<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const list = [
        { province: "山东", name: "yiyi" },
        { province: "山东", name: "erer" },
        { province: "山东", name: "sasa" },
        { province: "山西", name: "一" },
        { province: "湖北", name: "二" },
        { province: "河南", name: "三" },
        { province: "湖北", name: "四" },
      ];
      //遍历
      //如果存在当前省份，value++
      //如果不存，则把省份信息加进去，采用的格式是name=当前省份，value++
      //处理这个新的数据结构
      const newlist = [];
      list.forEach((item) => {
        //item={ province: "山东", name: "yiyi" },
        //判断遍历的item是否存在与新数组之中
        //新数组也要遍历
        const index = newlist.findIndex(
          (element) => element.name === item.province
        );
        if (index === -1) {
          newlist.push({ name: item.province, value: 1 });
        } else {
          newlist[index].value++;
        }
      });
      console.log(newlist);
    </script>
  </body>
</html>
